package com.example.xiaoshou.config;
 

import com.example.xiaoshou.service.KuCunService;
import com.example.xiaoshou.service.OrderService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

/**
 * 远程调用配置类
 */
@Configuration
public class MyConfig {
 
    @Bean
    public WebClient webClientKuCun(){
        return WebClient.builder()
                .baseUrl("http://localhost:8081")
                .build();
    }


    @Bean
    public WebClient webClientOrder(){
        return WebClient.builder()
                .baseUrl("http://localhost:8082")
                .build();
    }
 
    @Bean
    public KuCunService kuCunService(){
        //代理工厂 建造客户端 创建客户端对应的接口类
        HttpServiceProxyFactory httpServiceProxyFactory= HttpServiceProxyFactory
                .builder(WebClientAdapter.forClient(webClientKuCun())).build();
        return httpServiceProxyFactory.createClient(KuCunService.class);
    }

    @Bean
    public OrderService orderService(){
        //代理工厂 建造客户端 创建客户端对应的接口类
        HttpServiceProxyFactory httpServiceProxyFactory= HttpServiceProxyFactory
                .builder(WebClientAdapter.forClient(webClientOrder())).build();
        return httpServiceProxyFactory.createClient(OrderService.class);
    }
}